#include "StdAfx.h"
#include "interval_stack.h"
#include "tools.h"
#include "terrain_singleton.h"

interval_stack::interval_stack(void)
{
	rise = 0.0f;
	width_position_percent = 1.0f;
	radius = 0.01f;
}


interval_stack::~interval_stack(void)
{
}

void interval_stack::draw_element(float* position, float* delta, float* direction)
{
	glBindTexture(GL_TEXTURE_2D, texture);
	
	float root[3];
	float top[3];
	root[0] = position[0] + width_position_percent*delta[0];
	root[1] = position[1] + width_position_percent*delta[1] + rise;
	root[2] = position[2] + width_position_percent*delta[2];
	
	float terrain_height = terrain_singleton::get_height_at_position(root[0],root[2]);
	float delta_height = root[1] - terrain_height;

	if(delta_height > 0.2)
	{
		top[0] = root[0]; 
		top[1] = terrain_height;
		top[2] = root[2];
		draw_cylinder(top, root, radius, SECTION_DIRECTION_Y, true);
	}
	
	root[0] = position[0] - width_position_percent*delta[0];
	root[1] = position[1] - width_position_percent*delta[1] +rise;
	root[2] = position[2] - width_position_percent*delta[2];

	terrain_height = terrain_singleton::get_height_at_position(root[0],root[2]);
	delta_height = root[1] - terrain_height;

	if(delta_height > 0.2)
	{
		top[0] = root[0]; 
		top[1] = terrain_height;
		top[2] = root[2];
		draw_cylinder(top, root, radius, SECTION_DIRECTION_Y, true);
	}
}
